/**
 * 作者：陈文斌 on 2019/1/26.
 * 邮箱：chen_wennbin@163.com
 * 版本：v1.0
 */

import 'package:flutter/material.dart';
import 'package:crm/constant/constant.dart';
import 'package:crm/view/AppBar/custom_app_bar.dart';

const String Title = '客户群体';

class CustomerGroupPage extends StatefulWidget {
  final String customerGroupContent;
  final Function okCallback;

  CustomerGroupPage({
    Key key,
    this.customerGroupContent,
    @required this.okCallback,
  }) : super(key: key);

  @override
  State<StatefulWidget> createState() {
    return _CustomerGroupPageState();
  }
}

class _CustomerGroupPageState extends State<CustomerGroupPage> {
  String _customerGroupContent;

  @override
  void initState() {
    super.initState();
    _customerGroupContent = widget.customerGroupContent ?? '';
  }

  @override
  Widget build(BuildContext context) {
    TextEditingController _customerGroupEditingController =
        TextEditingController.fromValue(
      TextEditingValue(
        text: _customerGroupContent,
        selection: TextSelection.fromPosition(
          TextPosition(
              affinity: TextAffinity.downstream,
              offset: _customerGroupContent.length),
        ),
      ),
    );

    return Scaffold(
      appBar: CustomAppBar(
        title: Title,
        actions: <Widget>[
          MaterialButton(
            onPressed: () {
              widget.okCallback(_customerGroupContent);
              Navigator.pop(context);
            },
            child: Text(
              '完成',
              style: AppStyles.actionsTitleStyle,
            ),
            splashColor: Colors.transparent,
            highlightColor: Colors.transparent,
          ),
        ],
      ),
      body: GestureDetector(
        behavior: HitTestBehavior.translucent,
        onTap: () {
          FocusScope.of(context).requestFocus(FocusNode());
        },
        child: ListView(
          children: <Widget>[
            Container(
              width: MediaQuery.of(context).size.width,
              height: 176,
              color: Colors.white,
              padding: EdgeInsets.fromLTRB(16, 13, 16, 13),
              margin: EdgeInsets.only(top: 10),
              child: ConstrainedBox(
                constraints: BoxConstraints(
                  maxHeight: 150,
                ),
                child: TextField(
                  onChanged: (str) {
                    _customerGroupContent = str;
                  },
                  controller: _customerGroupEditingController,
                  decoration: InputDecoration(
                    border: InputBorder.none,
                    hintText: '请输入…',
                    hintStyle: TextStyle(
                      color: AppColors.PlaceholderTextColor,
                      fontSize: AppFontSizes.Font15,
                      fontFamily: AppFontFamilies.PingFangSC,
                      fontWeight: FontWeight.w500,
                    ),
                    contentPadding: EdgeInsets.zero,
                  ),
                  style: TextStyle(
                    color: AppColors.TextColor,
                    fontSize: AppFontSizes.Font15,
                    fontFamily: AppFontFamilies.PingFangSC,
                    fontWeight: FontWeight.w500,
                  ),
                  maxLines: null,
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }
}
